package com.dduggs.note.thread.suitangyinxiong;

public class Stage extends Thread {

    public void run() {

        System.out.println("欢迎观看隋唐演义");

        //观众安静片刻，等待大戏上演
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("大幕徐徐拉开");


        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("华硕隋朝末年，隋军与农民起义军杀的昏天黑地...");

        ArmyRunnable armytaskOfSuiDynasty = new ArmyRunnable();
        ArmyRunnable armytaskOfRevolt = new ArmyRunnable();

        //使用Runnable接口创建线程
        Thread armyOfSuiDynasty = new Thread(armytaskOfSuiDynasty, "隋军");
        Thread armyOfRevolt = new Thread(armytaskOfRevolt, "农民起义军");

        //启动线程，让军队开始作战
        armyOfSuiDynasty.start();
        armyOfRevolt.start();

        //舞台线程休眠，大家专心观看军队厮杀
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }



        Thread mrCheng =new KeyPersonThread();
        mrCheng.setName("程咬金");
        System.out.println("正当双方激战正酣，半路杀出了个程咬金！");

        //军队停止作战
        //停止线程的方法
        armytaskOfSuiDynasty.keepRunning = false;
        armytaskOfRevolt.keepRunning = false;
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //历史大戏留给关键人物
        mrCheng.start();

        //万众瞩目，所有线程等待程咬金完成历史使命
        try {
            mrCheng.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("战争结束，人们安居乐业，程咬金实现了积极的人生理想，为人民作出了贡献");
        System.out.println("谢谢观看隋唐演义，再见！");
    }

    public static void main(String[] args) {
        new Stage().start();
    }
}
